﻿var @(Model.ConfigInfo.EntityName)Manage = {};
(function (ns) {
    //加载树
    ns.initList = function () {
        
    }
    //加载数据
    ns.getDataList = function () {
        $("#datagrid").dataBind({
            url: '/@Model.ConfigInfo.ModelFolderName/@Model.ConfigInfo.EntityName/QueryPage',
            param: ns.getSearchCondition(),
        });
    }
    ns.resetSearch = function () {
        $('#searchForm').form('reset');
    }
    ns.reloadData = function () {
        $("#datagrid").datagrid("reload");
    }
    ns.getSearchCondition = function () {
        var opt = $('#searchForm').serializeObject();
        return opt;
    }
    //导入
    ns.import = function () {
        showWindow({ url: '/Common/Importpage/Importpage?imType=@(Model.ConfigInfo.TableName.ToLower())', title: '导入@(Model.ConfigInfo.TableComment)', width: 600, height: 320 });
    }
    ns.addData = function () {
        showWindow({ url: '/@Model.ConfigInfo.ModelFolderName/@Model.ConfigInfo.EntityName/Add', title: '新增@(Model.ConfigInfo.TableComment)', width: 600, height: 320 });
    }
    ns.editData = function (id) {
        showWindow({ url: '/@Model.ConfigInfo.ModelFolderName/@Model.ConfigInfo.EntityName/Edit?id=' + id, title: '编辑@(Model.ConfigInfo.TableComment)', width: 600, height: 320 });
    }
    ns.delData = function () {
        var rows = ns.getSelectedRows();
        if (rows.length <= 0) {
            showTig("请至少选择一行数据！", "error");
            return;
        }
        var ids = [];
        for (var i = 0; i < rows.length; i++) {
            //删除前校验

            ids.push(rows[i].Id);
        }
        return showConfirm('温馨提示', '确定要删除吗?', function () {
            $.ajax({
                url: '/@Model.ConfigInfo.ModelFolderName/@Model.ConfigInfo.EntityName/DeleteEntity',
                type: 'post',
                dataType: 'json',
                data: JSON.stringify({ ids: ids }),
                contentType: 'application/json',
                success: function (data) {
                    if (data > 0) {
                        ns.getDataList();
                    } else {
                        showTig('由于网络原因操作失败!', 'info');
                    }
                },
            });
        });
    }
    ns.getSelectedIDs = function () {
        var selRow = $("#datagrid").datagrid("getChecked");//返回选中多行
        var ids = [];
        for (var i = 0; i < selRow.length; i++) {
            ids.push(selRow[i].Id);
        }
        return ids;
    }
    ns.getSelectedRows = function () {
        var selRow = $("#datagrid").datagrid("getChecked");//返回选中多行
        return selRow;
    }
})( @(Model.ConfigInfo.EntityName)Manage);

$(function () {
    @(Model.ConfigInfo.EntityName)Manage.initList();
    @(Model.ConfigInfo.EntityName)Manage.getDataList();
});